package io.renren.modules.post.controller;

import com.alibaba.fastjson2.JSON;
import io.renren.common.utils.HttpClientUtils;
import io.renren.common.utils.Result;
import io.renren.modules.common.R;
import io.renren.modules.post.dto.PostDto;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/post")
public class PostController {
    @GetMapping
    public Result<List<PostDto>> list(){
        //远程调用获取数据
      String json= HttpClientUtils.getUrl("http://localhost:8083/sys/post/list");
        //把JSON字符串转成一个对象
        List<PostDto> postDtoList = JSON.parseArray(json, PostDto.class);
        return new Result().ok(postDtoList);

    }
    @PutMapping
    public Result<R> update(){
        //远程调用获取数据
        String json= HttpClientUtils.getUrl("http://localhost:8083/sys/post/update");
        List<R> r = JSON.parseArray(json, R.class);
        return new Result().ok(r);
    }
}
